package com.tiny.work.biz;

import com.tiny.work.biz.dao.TestMapper;
import com.tiny.work.biz.entity.Test;
import com.tiny.work.biz.entity.TestExample;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Component
public class TestDaoImpl implements TestDao, BeanPostProcessor, InitializingBean,
    ApplicationContextAware {

  @Autowired
  private TestMapper testMapper;

  @Autowired
  private InjectDaoImp injectDaoImp;


  @Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.NESTED,
      rollbackFor = Exception.class)
  @Override
  public void saveAndupdate() throws InterruptedException {
    TestExample record = new TestExample();
    record.createCriteria().andIdEqualTo(1);
    Test entity = new Test();
    Test dj_tes = new Test();
    dj_tes.setId(1);
    entity.setId(2);
    injectDaoImp.nested();
    injectDaoImp.nested2();
//    injectDaoImp.update();
//    testMapper.insertSelective(entity);
  }



  @Cacheable(key = "'name'", value = "default")
  @Override
  public List<Test> getTest(TestExample example) {
    return null;
  }

  @Override
  public void afterPropertiesSet() throws Exception {
    System.out.println("afterPropertiesSet");
  }

  @Override
  public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    System.out.println("setApplicationContext");

  }

  @Override
  public Object postProcessBeforeInitialization(Object bean, String beanName)
      throws BeansException {
    System.out.println("postProcessBeforeInitialization");
    return bean;
  }

  @Override
  public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    System.out.println("postProcessAfterInitialization");
    return bean;
  }
}
